var db = require( '../db/db' );

const tableName = 'core.app';

exports.getByName = async function ( name ) {
    var sql = `SELECT * FROM ${ tableName } WHERE name = $1`;
    var params = [ name ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "查询app出错" );
        return null;
    }
};


exports.plusUseCount = async function ( name ) {
    var sql = `UPDATE ${ tableName } SET use_count = use_count+1 WHERE name = $1`;
    var params = [ name ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( "app添加使用次数出错" );
        return null;
    }

};
